package com.konglz.publisher.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author konglz
 * @Data 2023/5/12 14:53
 */
@RestController
public class ConfirmMessageController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/confirm/{message}")
    @ApiOperation("测试生成者到交换机的信息确认")
    public void confrim(@PathVariable String message){
        String exchangeName = "demo_exchange_topic";
        //String message = "模块正在更新!";
        CorrelationData correlationData = new CorrelationData();
        correlationData.setReturnedMessage(new Message(message.getBytes()));
        //user.# topicQueue1能收到模块正在更新
        //rabbitTemplate.convertAndSend(exchangeName,"user.admin", message);
        //#.log topicQueue2收到模块正在更新
        //rabbitTemplate.convertAndSend(exchangeName,"log", message);
        //user.#、#.log topicQueue1、topicQueue2收到模块正在更新
        rabbitTemplate.convertAndSend(exchangeName,"aa.log", message, correlationData);
    }
}
